package com.softa.exception;

import com.softa.enummodel.ResponseErrorEnum;

import java.util.HashSet;
import java.util.Set;

/**
 * 通用的业务报错模型
 * 
 * @author Administrator
 *
 */
public class BusinessException extends Exception {
	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	/**
	 * 返回状态 0-有误，1-正常，2-警告
	 */
	private int stat;
	/**
	 * 返回携带的错误信息
	 */
	private Set<String> errorMessages;

	/**
	 * 业务错误类型
	 */
	private ResponseErrorEnum responseErrorType;

	public BusinessException() {
		super();
		this.stat = 1;
	}

	public BusinessException(String errorMessage) {
		super(errorMessage);
		this.stat = 0;
		HashSet<String> errs = new HashSet<String>();
		errs.add(errorMessage);
		this.errorMessages = errs;
	}

	public BusinessException(String errorMessage,
			ResponseErrorEnum responseErrorType) {
		super(errorMessage);
		this.stat = 0;
		HashSet<String> errs = new HashSet<String>();
		errs.add(errorMessage);
		this.errorMessages = errs;
		this.responseErrorType = responseErrorType;
	}

	public BusinessException(Set<String> errorMessages) {
		super(errorMessages.toString());
		this.stat = 0;
		this.errorMessages = errorMessages;
	}

	public int getStat() {
		return stat;
	}

	protected void setStat(int stat) {
		this.stat = stat;
	}

	/**
	 * 设置成警告模式
	 */
	public void setAsWarningMode() {
		stat = 2;
	}

	public Set<String> getErrorMessages() {
		return errorMessages;
	}

	protected void setErrorMessages(Set<String> errorMessages) {
		this.errorMessages = errorMessages;
	}

	public boolean hasError() {
		return stat == 0;
	}

	public boolean hasWarning() {
		return stat == 2;
	}

	public ResponseErrorEnum getResponseErrorType() {
		return responseErrorType;
	}

	public void setResponseErrorType(ResponseErrorEnum responseErrorType) {
		this.responseErrorType = responseErrorType;
	}
}
